//
//  DeskMeunCell.m
//  New_Runway
//
//  Created by mack on 2018/1/28.
//  Copyright © 2018年 NelsonJ. All rights reserved.
//

#import "DeskMeunCell.h"
#import "BagNumView.h"
#import "TargetModel.h"
@interface DeskMeunCell ()
@property (nonatomic, strong) BagNumView *redPoint;
@property (nonatomic, strong) NSString *type;
@property (weak, nonatomic) IBOutlet UILabel *carNum;

@end

@implementation DeskMeunCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    
    
}
-(void)setResourceRemark:(NSString *)resourceRemark{
    
    _resourceRemark = resourceRemark;
    NSDictionary *jsonDic = [self dictionaryWithJsonString:_resourceRemark];
    TargetModel *model = [[TargetModel alloc] init];
    [model setValuesForKeysWithDictionary:jsonDic];
    self.type = model.type;
}
-(void)setCarNumModel:(CarManagerNumModel *)carNumModel{
    _carNumModel = carNumModel;
    self.carNum.hidden = NO;
    if ([self.type isEqualToString:kCarNoLibary]){
        self.carNum.text = [NSString stringWithFormat:@"(%ld辆)",(long)carNumModel.initialNum];
    }else if ([self.type isEqualToString:kCarInLibaryApplying]) {
        self.carNum.text = [NSString stringWithFormat:@"(%ld辆)",(long)carNumModel.toStorageApplyNum];

    }else if ([self.type isEqualToString:kCarInLibary]) {
        self.carNum.text = [NSString stringWithFormat:@"(%ld辆)",(long)carNumModel.storageNum];

    }else if ([self.type isEqualToString:kCarOutLibary]) {
        self.carNum.text = [NSString stringWithFormat:@"(%ld辆)",(long)carNumModel.outStorageNum];

    }else if ([self.type isEqualToString:kCarOrder]) {
        self.carNum.text = [NSString stringWithFormat:@"(%ld辆)",(long)carNumModel.carOrderNum];

    }else{
        self.carNum.hidden = YES;
    }

}

-(void)setModel:(NoDealNumModel *)model{
    _model =model;
    _redPoint.hidden = NO;
   
    if ([self.type isEqualToString:kCrmWillAllotType]) {
        [self.iconIamge addSubview:self.redPoint];
        _redPoint.number = _model.xkhdfp;
        
    }else if ([self.type isEqualToString:kCrmStaffNoDealType]){
        [self.iconIamge addSubview:self.redPoint];
        _redPoint.number = _model.ygwcl;
        
    }else if ([self.type isEqualToString:kCrmNewAllotWillDealType]){
        [self.iconIamge addSubview:self.redPoint];
        _redPoint.number = _model.xfpdcl;
        
    }else if ([self.type isEqualToString:kCrmTodayDealType]){
        [self.iconIamge addSubview:self.redPoint];
        _redPoint.number = _model.jrwcl;
        
    }else if ([self.type isEqualToString:kCrmExpireNoDealType]){
        [self.iconIamge addSubview:self.redPoint];
        _redPoint.number = _model.gqwcl;
        
    }else{
        _redPoint.hidden = YES;
    }
    
}
-(BagNumView *)redPoint{
    
    if (!_redPoint) {
        _redPoint = [BagNumView showRedPointAndUnreadNumberViewWithLeftPoint:CGPointMake(CGRectGetMaxX(self.iconIamge.frame) - 30, 0)];
        _redPoint.backGroundView.backgroundColor = kColorRed();
    }
    return _redPoint;
}
-(NSDictionary *)dictionaryWithJsonString:(NSString *)jsonString {
    if (jsonString == nil) {
        return nil;
    }
    NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
    NSError *error;
    NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&error];
    if(error) {
        NSLog(@"json解析失败：%@",error);
        return nil;
    }
    return dic;
}


@end
